//
//  LOLversionViewController.m
//  LOLXXbox
//
//  Created by mac on 16/3/1.
//  Copyright © 2016年 Grasstrio. All rights reserved.
//

#import "LOLversionViewController.h"
#import "LSZNetWorkTools.h"
#import "LOLversionModel.h"
#import "LOLonlyTableViewCell.h"
#import "LOLFitCellHeight.h"
#define WIDTH [[UIScreen mainScreen]bounds].size.width
#define HEIGHT [[UIScreen mainScreen]bounds].size.height
#define TOPCHOOSEHEIGHT 30
#define TOPHEIGHT 64
#define VERSIONINFO(name) [NSString stringWithFormat:@"http://db.duowan.com/boxnews/heroinfo.php?name=%@",name]

#define BOTTOMHEIGHT 49
@interface LOLversionViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)NSMutableArray *versionArr;
@end

@implementation LOLversionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title=@"英雄改动";
    self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-TOPHEIGHT-BOTTOMHEIGHT) style:UITableViewStylePlain];
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    [self createData];

}

-(void)createData
{
    
//    [YMH_AFNetworkTool  getUrl:VERSIONINFO(self.enName) body:nil result:YMHJSON headerFile:nil success:^(id result) {
//        
//        self.versionArr=[YMH_versionInfoModel baseModelByArr:result[@"changeLog"]];
//        [self.tableView reloadData];
//        
//    } failure:^(NSError *error) {
//        
//    }];
    
    [LSZNetWorkTools getWithUrl:VERSIONINFO(self.enName) parameter:nil httpHeader:nil resposeType:ResponseTypeJSON success:^(id result) {
        
                self.versionArr=[LOLversionModel baseModelByArr:result[@"changeLog"]];
                [self.tableView reloadData];

        
    } fail:^(NSError *error) {
        
        
    }];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.versionArr.count;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse=@"versionReuse";
    LOLonlyTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell=[[LOLonlyTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }
    LOLversionModel *model=self.versionArr[indexPath.section];
    cell.wordLabel.text=model.info;
    
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    LOLversionModel *model=self.versionArr[indexPath.section];
    
    
    return [LOLFitCellHeight computeLabelString:model.info FontSize:14 width:WIDTH-10]+15;
    
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
    
    
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    LOLversionModel *model=self.versionArr[section];
    
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 20)];
    view.backgroundColor=[UIColor colorWithWhite:0.775 alpha:1.000];
    UILabel *versionLabel=[[UILabel alloc]initWithFrame:CGRectMake(5, 0, WIDTH/2, 30)];
    versionLabel.text=[NSString stringWithFormat:@"游戏版本V%@",model.version];
    versionLabel.font=[UIFont systemFontOfSize:14];
    versionLabel.textColor=[UIColor colorWithRed:0.173 green:0.678 blue:1.000 alpha:0.870];
    [view addSubview:versionLabel];

    
    NSDate *getTime=[NSDate dateWithTimeIntervalSince1970:model.time.integerValue];
    
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString *strDate=[formatter stringFromDate:getTime];
    

    
    UILabel *upDataLabel=[[UILabel alloc]initWithFrame:CGRectMake(WIDTH/2, 0,WIDTH/2-5,30)];
    upDataLabel.font=[UIFont systemFontOfSize:14];
    upDataLabel.textColor=[UIColor grayColor];
    upDataLabel.textAlignment=NSTextAlignmentRight;
    upDataLabel.text=[NSString stringWithFormat:@"更新时间: %@",strDate];
    [view addSubview:upDataLabel];

    
    
    
    
    return view;
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
